<template>
	<view class="container">
		<!-- <navbar :config="config"></navbar> -->
		<view class="containerView" :style="'height:' + sticky + 'px;padding-top:'+statusBarHeight +'px;'">
			<u-icon name="arrow-left" color="#020202" size="31" @click="backFun"></u-icon>

			<div class="search-box">
				<div class="search-wap">
					<!-- <text class="iconfont search-icon">&#xe7a6;</text> -->
					<image
						src="https://zhongyi-shop.oss-cn-beijing.aliyuncs.com/songhe/weixin/static/home/search-icon.png"
						style="width: 32rpx;height: 26rpx; margin-left: 6rpx;">
					</image>
					<input type="text" class="sput" placeholder-style="color: #474747;font-size: 28rpx"
						confirm-type="search" v-model="value" placeholder="请输入搜索关键字" @confirm="confirmSubmit" />
				</div>
				<div class="word" @click="SearchContent">搜索</div>
			</div>
		</view>
		<view class="zdtopbox">
			<!-- <view class="" style="display: flex;align-items: center;">
				<text class="iconfont position-ab u-mt15 u-ml30 u-D1D9D4">&#xe7a6;</text>
				<input placeholder="请输入搜索关键字" @confirm="confirmSubmit" v-model="value" placeholder-class="pc" />
				<text style="color: #FFFFFF;font-size: 28rpx; font-weight: 500;margin-left: 20rpx;align-items: center;" @click="SearchContent">搜索</text>
			</view> -->

			<view class="u-flex-center-sa">
				<view class="u-flex screen" @click="screening(1)"
					style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
					<view :class="screeningIndex == 1 ? 'activeColors' : ''">综合</view>
					<image :src="imgUrl+'/search/circularAic.png'" v-if="screeningIndex == 1"
						class="circularAic"></image>
				</view>
				<view class="u-flex-center screen" @click="screening(4)"
					style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
					<view :class="screeningIndex == 4 ? 'activeColors' : ''">销量</view>
					<image :src="imgUrl+'/search/circularAic.png'" v-if="screeningIndex == 4"
						class="circularAic"></image>
					<!-- <view class="u-flex-column-center ">
						<view class="iconfont u-font24 linge" :class="screeningIndex==2&&!selfNum?'activeColors':''">&#xeb20;</view>
						<view class="iconfont u-font24 linge" :class="screeningIndex==2&&selfNum?'activeColors':''">&#xeb1f;</view>
					</view> -->
				</view>
				<view class="u-flex-center screen" @click="screening(3)"
					style="display: flex;flex-direction: row;justify-content: center;align-items: center;">
					<view style="display: flex;flex-direction: column;justify-content: flex-start;align-items: center;">
						<view :class="screeningIndex == 3 ? 'activeColors' : ''">价格</view>
						<image :src="imgUrl+'/search/circularAic.png'" v-if="screeningIndex == 3"
							class="circularAic"></image>
					</view>
					<!-- <view class="linge-box">
						<view class="iconfont u-font24 linge"
							:class="screeningIndex == 3 && !price ? 'activeColorsXin' : ''">&#xe648;
						</view>
						<view class="iconfont u-font24 linge"
							:class="screeningIndex == 3 && price ? 'activeColorsXin' : ''">&#xe645;
						</view>
					</view> -->
				</view>
				<view class="u-flex screen" @click="screening(2)"
					style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
					<view :class="screeningIndex == 2 ? 'activeColors' : ''">新品</view>
					<image :src="imgUrl+'/search/circularAic.png'" v-if="screeningIndex == 2"
						class="circularAic"></image>
				</view>
			</view>
		</view>
		<view class="">
			<view class="productItme">
				<view class="itemp u-flex-center-sb " @click="goProductDetails(item, item.authorize_shop_id)"
					v-for="(item, index) in goodsList" :key="item.id">
						<image class="pImgs" :src="item.cover" mode=""></image>
						<!-- <view class="tipsImg u-flex-center">
								<image src="https://zhongyi-shop.oss-cn-beijing.aliyuncs.com/songhe/weixin/static/disbg.png" mode=""></image>
								<view class="u-FFF u-font24 textpiv">4.5折</view>
							</view> -->
					<view class="u-flex1 u-flex-column-start">
						<view class="proWidth u-display1">
							<view class="tipsStatus" v-if="item.platform_store">自营</view>
							<text class="proWidthTitle">{{ item.title }}</text>
						</view>
						<view class=" u-flex-center priceView" >
							<rich-text :nodes="$mUtil.priceBigSmall(item.min_sale_price)"></rich-text>
							<text class="marketPrice">￥{{ item.max_market_price }}</text>
						</view>
						
						<view class="sold">
							已售
							<text >{{ item.result_sale_num }}</text>
							件
						</view>
						<view class="good-praise" >
							<text >{{ item.comment_num }}</text>
							条评论 评分:
							<text 
								v-if="item.average % 1 === 0">{{ item.average }}.0</text>
							<text v-else >{{ item.average }}</text>
						</view>
						<view class="store" @click.stop="goTobusiness(item.shop_id)"
							>
							{{ item.shop_name }}
							<image :src="imgUrl+'/personal/right.png'" class='rightImage'></image>
						</view>
					</view>
				</view>
				<nodata v-if="noData" :config="{ top: 20, content: '暂无商品~' }"></nodata>
				<loadMore v-if="goodsList.length > 0" :status="status"></loadMore>
			</view>
		</view>
		<!--页面加载动画-->
		<ldLoading isFullScreen :active="loading"></ldLoading>
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				imgUrl: this.$mConfig.staticUrl,
				config: {
					back: true, //false是tolbar页面 是则不写
					title: '商品列表',
					color: '#FFFFFF',
					//背景颜色;参数一：透明度（0-1）;参数二：背景颜色（array则为线性渐变，string为单色背景）
					backgroundColor: [1, '#FF721B'],
					statusBarFontColor: '#FFFFFF'
				},
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
				sticky: uni.getSystemInfoSync().statusBarHeight + 60,
				goodsList: [],
				score: null,
				loading: true,
				noData: false,
				value: '',
				status: 'more', //more|loading|noMore
				screeningIndex: 1,
				price: false,
				selfNum: false,
				tabTop: 0,
				params: {
					limit: 10,
					page: 1,
					order_type: 1, //1是综合（按发布时间），2是新品，3价格，4销量
					order_mode: '' //asc 或 desc
				}
			};
		},
		onLoad(options) {
			this.tabTop = app.globalData.barHeight + 44;
			if (options.keyword) {
				this.params.title = options.keyword;
				this.value = options.keyword || '';
			}
			if (options.category_id) {
				this.params.category_id = options.category_id;
			}
			this.getShopList();
			console.log(options)
		},
		onReachBottom(e) {
			this.status = 'loading';
			this.params.page++;
			this.getShopList();
		},
		onPullDownRefresh() {
			this.rest();
			this.getShopList();
		},
		methods: {
			backFun() {
				uni.navigateBack({
					delta: 1
				})
			},
			//跳转商家店面
			goTobusiness(id) {
				console.log(id);
				uni.navigateTo({
					url: '/pages/convenienceService/shopDetails?shopId=' + id
				});
			},
			//普通商品详情页
			goProductDetails(item, shopid) {
				uni.navigateTo({
					url: `/pages/product/goods/goods?id=${item.id}`
				})
				// 积分商品
				// if (item.point_goods) {
				//   uni.navigateTo({
				//     url: `/pages/product/goods/IntegralGood?id=${item.id}`
				//   })
				//   // 免费商品
				// } else if (item.free) {
				//   uni.navigateTo({
				//     url: `/pages/product/goods/freeGoods?id=${item.id}`
				//   })
				//   // 普通商品
				// } else {
				//   uni.navigateTo({
				//     url: `/pages/product/goods/goods?id=${item.id}`
				//   })
				// }
			},

			screening(e) {
				this.loading = true;
				this.params.order_type = e;
				this.screeningIndex = e;
				// if(e==2){
				// 	this.selfNum =!this.selfNum
				// 	if(this.selfNum){
				// 		this.params.order_mode='asc'
				// 	}else{
				// 		this.params.order_mode='desc'
				// 	}
				// }else
				if (e == 3) {
					this.price = !this.price;
					if (this.price) {
						this.params.order_mode = 'desc';
					} else {
						this.params.order_mode = 'asc';
					}
				} else if (e == 4) {
					this.params.order_mode = 'desc';
				} else {
					this.params.order_mode = '';
				}
				this.rest();
				this.getShopList();
			},
			//搜索返回的数据
			confirmSubmit(e) {
				this.params.title = e.detail.value;
				this.value = e.detail.value;
				this.rest();
				this.getShopList();
			},
			SearchContent() {
				this.params.title = this.value;
				this.rest();
				this.getShopList();
			},
			rest() {
				this.params.page = 1;
				this.goodsList = [];
			},
			getShopList() {
				let shop = uni.getStorageSync('shop');
				let shopid = shop.id ? shop.id : '';
				this.$http.get(`/goods/all/pages`, this.params).then(res => {
					uni.stopPullDownRefresh();
					this.loading = false;
					this.triggered = false;
					if (res && res.code == 200) {
						if (res.page.list.length > 0) {
							if (this.params.title) {
								this.reset(this.params.title);
							}
						}
						this.goodsList = this.goodsList.concat(res.page.list);

						if (this.goodsList.length == 0) {
							this.noData = true;
						} else {
							this.noData = false;
						}
						if (res.page.totalPage <= res.page.currPage) {
							this.status = 'noMore';
						} else {
							this.status = 'more';
						}
					}
				});
			},
			reset(text) {
				let recordList = uni.getStorageSync('history') ? uni.getStorageSync('history') : [];
				recordList.unshift(text);
				let arr = JSON.parse(JSON.stringify(recordList));
				let newArr = Array.from(new Set(arr));
				recordList = newArr;
				uni.setStorageSync('history', JSON.parse(JSON.stringify(recordList)));
			}
		}
	};
</script>

<style lang="scss">
	// page {
	//   background-color: #f5f5f5;
	// }


	.hx-navbar {
		/deep/ .hx-navbar__content {
			background-color: #FF721B !important;

			.hx_text_overflow {
				color: #fff !important;
			}
		}
	}

	.search-box {
		// height: 85rpx;
		// padding: 0 30rpx;
		width: 100%;
		background-color: #fff;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		margin-left: 25rpx;

		// align-items: center;
		.search-wap {
			width: 560rpx;
			height: 65rpx;
			background: #F5F5F5;
			border-radius: 15rpx 15rpx 15rpx 15rpx;
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: center;
			padding-left: 19rpx;

			// display: flex;
			// align-items: center;
			// border: 1rpx solid #F4F4F4;
			// position: relative;

			.search-icon {
				font-size: 36rpx;
				margin-left: 30rpx;
				color: #fff;
			}

			.sput {
				margin-left: 12rpx;
				font-size: 28rpx;
				color: #474747;
				width: 100%;
			}
		}

		.word {
			font-size: 28rpx;
			color: #000;
			margin-left: 24rpx;
			line-height: 60rpx;
		}
	}

	.linge-box {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: center;
		height: 28rpx;
		margin-left: 4rpx;
	}

	.linge {
		line-height: 14rpx;
		font-size: 15rpx;
	}

	.position-ab {
		position: absolute;
	}

	.bg-F6F6F6 {
		background-color: #F6F6F6;

		.u-flex:nth-of-type(1),
		.u-flex-center {
			position: relative;

			&::before {
				content: '';
				position: absolute;
				top: 8rpx;
				left: 120rpx;
				width: 1rpx;
				height: 20rpx;
				background-color: #AAAAAA;
				// background: #ffffff;
			}
		}

		.u-flex-center:last-child {
			&::before {
				content: none;
			}
		}
	}

	.pt80 {
		padding-top: 180rpx;
	}

	.zdtopbox {
		// padding: 8rpx 30rpx 10rpx;

		box-sizing: border-box;

		// input {
		// 	flex: 1;
		// 	height: 60rpx;
		// 	line-height: 60rpx;
		// 	border-radius: 50rpx;
		// 	background-color: rgba($color: #abc5b5, $alpha: 0.4);
		// 	color: #fff;
		// 	padding-left: 78rpx;
		// 	box-sizing: border-box;
		// }

		.pc {
			font-size: 22rpx;
			color: #abc5b5 !important;
		}

		.wt-ht8 {
			width: 16rpx;
			height: 16rpx;
		}
	}

	.oval {
		background-color: #f5f5f5;
		padding: 18rpx 38rpx;
		border-radius: 50rpx;
		margin-top: 30rpx;
		margin-right: 22rpx;
	}

	.itemp {
		width: 712rpx;
		height: 250rpx;
		background: #FFFFFF;
		border-radius: 19rpx 19rpx 19rpx 19rpx;
		box-sizing: border-box;
		margin-left: 19rpx;
		margin-top: 19rpx;
	}

	.pImgs {
		// position: relative;
		width: 212rpx;
		height: 212rpx;
		margin-left: 19rpx;
		margin-right: 19rpx;
		border-radius: 20rpx;
		// .tipsImg {
		// 	width: 96rpx;
		// 	height: 44rpx;
		// 	// position: absolute;
		// 	// left: 0;
		// 	// bottom: 0;

		// 	image {
		// 		width: 96rpx;
		// 		height: 44rpx;
		// 		// position: absolute;
		// 		// z-index: 0;
		// 	}

		// 	.textpiv {
		// 		width: 96rpx;
		// 		text-align: center;
		// 		position: relative;
		// 		z-index: 1;
		// 	}
		// }
	}

	.proWidth {
		width: 437rpx;
		height: 27rpx;
		line-height: 27rpx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		.tipsStatus {
			padding:8rpx 11rpx;
			height: 27rpx;
			background: #FF211F;
			border-radius: 6rpx 6rpx 6rpx 6rpx;
			font-weight: 500;
			font-size: 17rpx;
			color: #FFFFFF;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			width: 60rpx;
		}
	}
	.proWidthTitle{
		font-weight: 600;
		font-size: 27rpx;
		color: #333333;
		width: 367rpx;
		height: 27rpx;
		box-sizing: border-box;
		line-height: 27rpx;
	}
	

	.activeColors {
		font-weight: 600;
		font-size: 29rpx;
		color: #FF211F;
	}

	.activeColorsXin {
		font-weight: 600;
		// font-size: 20rpx;
		color: red;
	}

	.container {}

	.u-flex-center-sa {
	}

	.screen {
		width: 188rpx;
		// height: 70rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
		margin-top: 20rpx;
	}

	.productItme {
		margin-top: 19rpx;
	}

	.containerView {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		background: #fff;
		padding: 10px 0;
		padding-left: 25rpx;
		width: 100%;
	}

	.circularAic {
		width: 20rpx;
		height: 6rpx;
		margin-top: 6rpx;
	}
	.priceView{
		font-weight: bold;
		font-size: 27rpx;
		color: #FF211F;
		line-height: 27rpx;
		margin-top: 19rpx;
	}
	.marketPrice{
		font-weight: 400;
		font-size: 23rpx;
		color: #BCBCBC;
		line-height: 17rpx;
		margin-left: 6rpx;
	}
	.sold{
		font-weight: 400;
		font-size: 23rpx;
		color: #999999;
		line-height: 23rpx;
		margin-top: 19rpx;
		text{
			color: #FF211F;
			padding:0 10rpx;
		}
	}
	.good-praise{
		font-weight: 400;
		font-size: 23rpx;
		color: #999999;
		line-height: 23rpx;
		margin-top: 19rpx;
		margin-bottom: 19rpx;
	}
	.store{
		font-weight: 400;
		font-size: 25rpx;
		color: #333333;
		line-height: 23rpx;
	}
	.rightImage{
		width: 8rpx;
		height:16rpx;
		margin-left: 12rpx;
	}
</style>